home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / YBIFM.C < prev    next >
C/C++ Source or Header  |  1988-11-28  |  12KB  |  418 lines

  1.  
  2. /********************************* YBIFM.C ***********************************/
  3. /********************* (C) 1986,7,8 by JAMES A. YORKE ************************/
  4.  
  5. #include "yinclud.h"
  6.  
  7. #define PRINTWIDTH 260
  8. #define WIDTH 700
  9. #define BIF_PRE_ITERATES 200
  10. #define BIF_ITERATES     700
  11. #define BIF_LINES 400
  12.  
  13. static int      borderFlag = YES;/* cannot be changed; this determines if a
  14.                    border is drawn */
  15. static int      Contin,
  16.                 threshhold = CORECOLS;
  17. static int      border = PRINTWIDTH;
  18. static char     bifP[CORECOLS];    /* 960 */
  19. static double   firstrho = -9999.,
  20.                 lastrho = -9999.;
  21. static long     m,
  22.                 printerLines,
  23.                 bifLines = BIF_LINES;
  24. long    bifPreIterates = BIF_PRE_ITERATES,
  25.         bifIterates = BIF_ITERATES;
  26. static int      bifFlag = ON;
  27.  
  28. bif() 
  29. {
  30.     double  oldrho = rho;    /* save current value */
  31.     char    maskChar;
  32.     int     i,
  33.             j,
  34.             n,
  35.             prt,
  36.             cs;
  37.     long    ii,
  38.             k;
  39.     double  drho,
  40.             dx,
  41.             h;
  42.     FILE    *prn;
  43.     unsigned        counter,
  44.                     totalCount[8];
  45.     int     didprint = NO;
  46.     int     level1;
  47.  
  48.     level1 = ++level;
  49.  
  50.     printerLines = bifLines / 8;
  51.     Contin = YES;
  52.  
  53.     counter = 0;
  54.     if(firstrho == -9999.|| lastrho == -9999.) {
  55.         PRINT
  56.             " You must first give beginning and ending values for rho \n");
  57.         PRINT "Use command BIFS(BIFurcation Scale) \n");
  58.         return;
  59.     }
  60.     if(firstrho == lastrho) {
  61.         PRINT
  62.             "The beginning and last rho CANNOT be equal; set using BIFS \n");
  63.         return;
  64.     }
  65.     if(X_coord < 0) {
  66.         PRINT
  67.             "The X_coord number(now = %d) cannot be < 0 ; reset using command COORDS \n"
  68.             ,X_coord);
  69.         return;
  70.     }
  71.     prn = stdprn;
  72.     if(bifFlag == OFF)
  73.         border = 0;    /* parameter will not be printed out */
  74.     i12print();        /* tells printer to use regular spacing(for
  75.                    text) */
  76.  
  77.  
  78.     printf(
  79.             "*********************************************************************\n");
  80.     printf(
  81.             "*      This routine is for creating bifurcation diagrams, i.e.      *\n");
  82.     printf(
  83.             "*  the X coordinate of the process is plotted horizontally on paper *\n");
  84.     printf(
  85.             "*               using an Epson printer or compatible                *\n");
  86.     printf(
  87.             "*            and the parameter rho is varied vertically             *\n");
  88.     printf(
  89.             "*********************************************************************\n");
  90.     printf(" \n");
  91.  
  92.     printf(" \n");
  93.     bifTextFlag = ON;
  94.     print_text(stdout);    /* prints text header at top of picture */
  95.     print_text(prn);    /* prints text header at top of picture */
  96.     bifTextFlag = OFF;
  97.     if(bifLines != 1)
  98.         printf("rho runs from %13.13lf to %13.13lf in steps of %13.13lf \n",
  99.                 firstrho, lastrho, (lastrho - firstrho) / (bifLines - 1));
  100.     printf("plotting X = y[%d]  \n", X_coord);
  101.     printf("%ld preiterates;  %ld bifIterates; %ld values of rho\n\n"
  102.             ,bifPreIterates, bifIterates, bifLines);
  103.  
  104.     if(bifLines > 1)
  105.         fprintf(prn,
  106.                 "rho runs from %15.13lf to %15.13lf in steps of %13.13lf;\n",
  107.                 firstrho, lastrho, (lastrho - firstrho) / (bifLines - 1));
  108.     fprintf(prn, "plotting X = y[%d]  \n", X_coord);
  109.     fprintf(prn, "%ld preiterates; %ld iterates; %ld values of rho\n\n\n\n",
  110.             bifPreIterates, bifIterates, bifLines);
  111.  
  112.  
  113.     drho = (lastrho - firstrho) / (8 * printerLines - 1);
  114.                 /* drho is the change in rho; the number of
  115.                    steps is printerLines*8  -1; */
  116.     dx = WIDTH / (X_upper - X_lower);
  117.     h = -dx * X_lower;
  118.  
  119.     iprint(printerSpacing);/* in YPRINTER.C, initializes printer spacing
  120.                    for graphics */
  121.  
  122.     for(m = 0; m < printerLines && Contin == YES && level >= level1
  123.             ; m = m + 1) {
  124.         for(i = 0; i < printerWidth; i++)
  125.             bifP[i] = 0;
  126.         if(borderFlag == YES)
  127.             bifP[border] = bifP[printerWidth - 1] = 255;
  128.                 /* all bits = 1 */
  129.         rho = 8.* drho * m + firstrho;
  130. #ifdef MS
  131.         fflush(stdprn);
  132. #endif
  133.         for(n = 0; n <= 7 && Contin == YES && level >= level1
  134.                 ; n = n + 1) {
  135. #ifndef MAINFRAME
  136.             if(ChkKeyStatus() != 0 || cycle > 0)
  137.                 Interrupt();
  138. #endif
  139.             j = 8 * m + n;
  140.             rho = drho * j + firstrho;
  141.             maskChar = mask[n];
  142.  
  143.             if(InitFlag == ON)
  144.                 store(y, y + eqnsL, dim);/* initialize y */
  145.             for(k = 1; k <= bifPreIterates; k = k + 1) {
  146.                 (*iteratee) ();
  147.             }
  148.             if(threshhold < printerWidth) {
  149.  
  150.                 counter = 0;
  151.                 for(k = 1; k <= bifIterates; k++) {
  152.                     (*iteratee) ();
  153.                     i = ii = dx * y[X_coord] + h + border;
  154.                 /* effective WIDTH is printerWidth -border,
  155.                    which may not be printerWidth; integer part
  156.                    should be a long */
  157.                     if(ii >= border
  158.                             && ii < printerWidth) {
  159.                         if((bifP[i] & maskChar) == 0) {
  160.                             bifP[i] = bifP[i] | maskChar;
  161.                             counter++;
  162.                         }
  163.                     }
  164.                 }
  165.                 totalCount[n] = counter;
  166.             }    /* end if threshhold < printerWidth */
  167.             if(threshhold >= printerWidth) {
  168.                 /* then ignore threshhold */
  169.                 for(k = 1; k <= bifIterates; k++) {
  170.                     (*iteratee) ();
  171. /*if(printer == 1)
  172. printf(": k=%ld,x=%lf        \r",k,y[X_coord]);
  173. */
  174.                     i = ii = dx * y[X_coord] + h + border;
  175.                 /* effective WIDTH is printerWidth -border,
  176.                    which may not be printerWidth; integer part
  177.                    should be a long */
  178.                     if(ii >= border
  179.                             && ii < printerWidth)
  180.                         bifP[i] = bifP[i] | maskChar;
  181.                 }
  182.             }    /* end if threshhold >= printerWidth */
  183.             cs = keycheck();
  184.             if(cs == ESC || cs == ' ') {
  185.                 /* is printing being interrupted? Note Esc = 27
  186.                    */
  187.                 Contin = NO;
  188.                 /* space bar stops printing and returns program
  189.                    to parameter selection */
  190.             }
  191.         }
  192.         if(printer > 1 && threshhold < printerWidth)
  193.             printf(
  194.                     "\rrho=%9.9lf count=%d,%d,%d,%d,%d,%d,%d,%d,thresh=%d__"
  195.                     ,rho, totalCount[0], totalCount[1], totalCount[2], totalCount[3]
  196.                     ,totalCount[4], totalCount[5], totalCount[6], totalCount[7], threshhold);
  197.         if(printer > 1 && threshhold >= printerWidth)
  198.             printf(
  199.                     "\rrho=%9.9lf ", rho);
  200.         if(Contin == YES) {
  201.             if(threshhold >= printerWidth ||
  202.                     (totalCount[0] <= threshhold ||
  203.                         totalCount[1] <= threshhold ||
  204.                         totalCount[2] <= threshhold ||
  205.                         totalCount[3] <= threshhold ||
  206.                         totalCount[4] <= threshhold ||
  207.                         totalCount[5] <= threshhold ||
  208.                         totalCount[6] <= threshhold ||
  209.                         totalCount[7] <= threshhold)) {
  210.                 if(bifFlag == ON)
  211.                     for(prt = 1; prt == 1 || prt <= onprint; prt++)
  212.                         fprintf(prn, "rho=%14.14lf\r", rho);
  213.                 multi_strike();
  214.                 didprint = YES;
  215.             }
  216.             else {    /* we skip a line after each break in printing 
  217.                 */
  218.                 if(didprint == YES)
  219.                     fprintf(prn, "skip\n");
  220.                 didprint = NO;
  221.             }
  222.         }        /* end if Contin */
  223.     }
  224.     i12print();        /* tells printer to return to regular spacing 
  225.                 */
  226.     printf(" \n");
  227.     fprintf(prn, "\n\n\n\n\n");
  228.     rho = oldrho;        /* restore original value */
  229. #ifdef MS
  230.     fflush(stdprn);
  231. #endif
  232.     level = level1 - 1;
  233. }
  234.  
  235.  
  236. multi_strike() {        /* similar to vprint */
  237.     int     i,
  238.             prt;
  239.     for(prt = 1; (prt == 1 || prt <= onprint) && Contin == YES; prt++) {
  240.         print_graphics_mode();
  241.  
  242.         for(i = 0; i < printerWidth; i = i + 1) {
  243.             C = bifP[i];
  244. #ifndef X11
  245.             printChar();
  246. #endif
  247.         }
  248.         carriage_return();
  249.     }
  250.     line_feed();        /* line feed */
  251. }
  252.  
  253.  
  254.  
  255. bifdisk(fff)            /* for disk printing for DD and TD commands;
  256.                    called in YDISK.C */
  257. FILE * fff;
  258. {
  259.     if(firstrho != -9999.|| lastrho != -9999.)
  260.         fprintf(fff,
  261.                 "BIFS  %15.15lf %15.15lf /* BIF parameter Scale */ \n", firstrho, lastrho);
  262.  
  263.     if(bifFlag == OFF)
  264.         fprintf(fff,
  265.                 "BIFP /* toggle turns off feature where BIF prints parameters with pic */ \n");
  266.  
  267.     if(bifPreIterates != BIF_PRE_ITERATES || bifIterates != BIF_ITERATES)
  268.         fprintf(fff,
  269.                 "BIF2   %ld %ld  /* preiterates,  iterates  */\n"
  270.                 ,bifPreIterates, bifIterates);
  271.  
  272.     if(bifLines != BIF_LINES)
  273.         fprintf(fff,
  274.                 "BIFL   %ld /*   =  the number of values of rho */\n"
  275.                 ,bifLines);
  276.  
  277.     if(threshhold != CORECOLS)
  278.         fprintf(fff,
  279.                 "BIFT   %d /*  threshhold value below which we print */\n"
  280.                 ,threshhold);
  281. }
  282.  
  283.  
  284. setdots(numRhos)        /* for trajectory() in Y.C, for plotting
  285.                    bifuracation diagrams on the screen; this is
  286.                    here because the two bif... variables are
  287.                    static and cannot be accessed from Y.C */
  288. int     numRhos;
  289. {
  290.     dots = numRhos * (bifPreIterates + bifIterates);
  291. }
  292.  
  293.  
  294. int     bifCommands(CodeName)     /* called from YCOMNDS.C */
  295. char    *CodeName;
  296. {
  297.     TEST("bif") {    /* command to have the printer make a strip map */
  298.         bif();    /* in YBIFM.C */
  299.         return(1);
  300.     }
  301.     TEST("bifi") {
  302.         InitFlag = 1 - InitFlag;
  303.         if(SCREEN) {
  304.             PRINT "Flag for reinitializing y for each rho is now");
  305.             toggle(InitFlag);
  306.         }
  307.         return(1);
  308.     }
  309.     TEST("bifp") {
  310.         bifFlag = 1 - bifFlag;
  311.         if(SCREEN) {
  312.             PRINT
  313.                 "Flag for printing parameter values continuously is now\n");
  314.             toggle(bifFlag);
  315.         }
  316.         return(1);
  317.     }
  318.     TEST("bifs") {        /* parameter scale for bifurcation strip */
  319.         EnterScale(&firstrho, &lastrho);
  320.         return(1);
  321.     }
  322.     TEST("bif2") {        /* sets preiterates and iterates */
  323.         bif2 ();    /* in YBIFRCAT.C */
  324.         return(1);
  325.     }
  326.  
  327.     TEST("bifl") {        /* sets number if printer lines */
  328.         if(SCREEN)
  329.             printf(
  330.                     "Enter the number of lines, i.e. the number of values of rho\n");
  331.         bifLines = (long) Entervalue((double) bifLines, CHECKSET);
  332.         printerLines = bifLines / 8;
  333.         return(1);
  334.     }
  335.     TEST("bift") {        /* sets threshhold number for printing 8 lines 
  336.                 */
  337.         threshhold = (int) Entervalue((double) threshhold, CHECKSET);
  338.         return(1);
  339.     }
  340.     return(0);
  341. }
  342.  
  343. bifMenu() {            /* call ed by command BIFM */
  344.     if(level == SETPARAM)
  345.         scr_clr();    /* in desmets pcio.a */
  346.     scr_rowcol(1, 0);
  347.     PRINT
  348.         "     BIFURCATION MENU FOR MAKING BIFURCATION DIAGRAMS\n\n");
  349.     PRINT
  350.         " \n");
  351.     PRINT
  352.         " BIF2: set preiterates and iterates, now %ld,%ld\n"
  353.         ,bifPreIterates, bifIterates);
  354.     PRINT
  355.         " BIFI: re-Initialize y[] for each rho, currently");
  356.     toggle(InitFlag);
  357.     PRINT
  358.         "\nThe following BIFx commands are ONLY for diagrams made on the PRINTER \n");
  359.  
  360.     PRINT
  361.         " BIF:  makes a BIFurcation diagram on the printer\n");
  362.     PRINT
  363.         " BIFL: set lines, (about 720 per page); now = %ld\n"
  364.         ,bifLines);
  365.     PRINT
  366.         " BIFP: Print Parameter values as the strip is plotted, currently");
  367.     toggle(bifFlag);
  368.     PRINT
  369.         " BIFS: Scale, i.e., the range of parameter, now %lf to %lf\n"
  370.         ,firstrho, lastrho);
  371.     PRINT
  372.         " BIFT: prints data only if 1 of 8 lines has <= Threshhold dots, now = %d\n"
  373.         ,threshhold);
  374.     PRINT
  375.         "\nUseful commands in other menus: \n");
  376.     PRINT
  377.         " COORDS: changes X and Y coordinates; printer plots only the X coord.,y[%d]\n"
  378.         ,X_coord);
  379.  
  380.     PRINT
  381.         " PH:   the number of times the Printer Head strikes each dot; now = %d\n"
  382.         ,onprint);
  383.     PRINT
  384.         " XS:   X Scale: X_left = %lf; X_right= %lf   MUST be set\n"
  385.         ,X_Lo[ScrnSec], X_Up[ScrnSec]);
  386.  
  387.     PRINT
  388.         "\n YS:   Y Scale: Y_lower = %lf Y_upper = %lf -- NOT needed for 'BIF'\n\n"
  389.         ,Y_Lo[ScrnSec], Y_Up[ScrnSec]);
  390. }
  391.  
  392.  
  393.  
  394. bif2 () {            /* to execute command BIF2 */
  395.     if(SCREEN) {
  396.         printf(
  397.                 "%ld preiterates followed by  %ld iterates for each value of rho\n"
  398.                 ,bifPreIterates, bifIterates);
  399.         printf("  An example of input(both on one line):\n");
  400.         printf("    200   700  <return> (no comma) \n");
  401.         printf(
  402.                 " that is, 200 preiterates before plotting plus  700 iterates for each rho\n");
  403.         printf("ENTER 2 INTEGER VALUES \n");
  404.     }
  405. #ifdef X11
  406.     if((input == StInput && sscanf(xwfgets(), "%ld %ld", 
  407.        &bifPreIterates, &bifIterates) == 2 || input != StInput &&
  408.         fscanf(input, "%ld %ld", &bifPreIterates, &bifIterates) == 2)
  409. #else
  410.     if(abortEnter() == NO &&
  411.         fscanf(input, "%ld %ld", &bifPreIterates, &bifIterates) == 2
  412. #endif
  413.        && SCREEN) {
  414.         printf("%ld preiterates followed by  %ld iterates for each value of rho\n",
  415.                 bifPreIterates, bifIterates);
  416.     }
  417. }
  418.